package wechat.handler.request.template.impl;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;

import wechat.handler.bean.request.template.SetIndustryBean;
import wechat.handler.bean.request.template.TemplateInfoBean;
import wechat.handler.bean.request.template.TemplateValueBean;
import wechat.handler.bean.request.template.instance.PayNoticeBean;
import wechat.handler.bean.request.template.instance.VerifyNoticeBean;
import wechat.handler.request.base.BaseTemplate;
import wechat.handler.request.template.ITemplate;
import wechat.handler.util.type.TemplateType;

public class Template extends BaseTemplate implements ITemplate {
	private Logger log = LoggerFactory.getLogger(Template.class);
	
	public boolean setIndustry(SetIndustryBean setIndustryBean) throws Exception {
		String jsonString = JSON.toJSONString(setIndustryBean);
		
		log.info("Template--setIndustry  jsonString=" + jsonString);
		
		return super.setIndustry(jsonString);
	}
	
	public boolean setIndustry(String appid,SetIndustryBean setIndustryBean) throws Exception {
		String jsonString = JSON.toJSONString(setIndustryBean);
		
		log.info("Template--setIndustry appid="+appid+" jsonString=" + jsonString);
		
		return super.setIndustry(appid,jsonString);
	}
	
	public String addTemplate(String templateIdShort) throws Exception {
		JSONObject param = new JSONObject();
		param.put("template_id_short", templateIdShort);
		
		log.info("Template--addTemplate  templateIdShort=" + templateIdShort + " param=" + param);
		
		return super.addTemplate(param.toJSONString());
	}
	
	public String addTemplate(String appid,String templateIdShort) throws Exception {
		JSONObject param = new JSONObject();
		param.put("template_id_short", templateIdShort);
		
		log.info("Template--addTemplate appid="+appid+" templateIdShort=" + templateIdShort + " param=" + param);
		
		return super.addTemplate(appid,param.toJSONString());
	}
		
	public boolean sendTemplate(TemplateInfoBean templateInfoBase) throws Exception {
		String param = JSON.toJSONString(templateInfoBase);

		log.info("Template--sendTemplate  param=" + param);
		
		super.sendTemplate(param);
		return true;
	}
	
	public boolean sendTemplate(String appid,TemplateInfoBean templateInfoBase) throws Exception {
		String param = JSON.toJSONString(templateInfoBase);

		log.info("Template--sendTemplate appid="+appid+" param=" + param);
		
		super.sendTemplate(appid,param);
		return true;
	}
	
	public static void main(String[] args) throws Exception {

		ITemplate template = new Template();

		PayNoticeBean payTemplate = new PayNoticeBean();
//		VerifyNoticeBean payTemplate = new VerifyNoticeBean();
		TemplateInfoBean parent = new TemplateInfoBean(TemplateType.Verify);
		
		//parent.setTemplate_id(VerifyNoticeBean.Template_Id);
		parent.setTouser("oWCXUvzqzUu90RDnPp60J8luqvBc");
		parent.setUrl("http://www.baidu.com");
		
		TemplateValueBean childrenBean = new TemplateValueBean();
		childrenBean.setValue("1");
		payTemplate.setFirst(childrenBean);
		
		childrenBean = new TemplateValueBean();
		childrenBean.setValue("2");
		payTemplate.setKeyword1(childrenBean);
		
		childrenBean = new TemplateValueBean();
		childrenBean.setValue("2");
		payTemplate.setKeyword2(childrenBean);
		
		childrenBean = new TemplateValueBean();
		childrenBean.setValue("2");
		payTemplate.setKeyword3(childrenBean);
		
		childrenBean = new TemplateValueBean();
		childrenBean.setValue("点击修改");
		payTemplate.setRemark(childrenBean);
		
		parent.setData(payTemplate);
		
		//System.out.println(JSON.toJSONString(parent));
		template.sendTemplate(parent);
		
	}
}
